(function (_super) {
    // 10001	糖果boss
    // 10002	章鱼boss
    // 10003	章鱼小弟没头脑
    // 10004	章鱼小弟不高兴
    // 10005	机械boss

    function Monster(data) {
        Monster.super(this);

        this.type = null;
        this.boss = null;
        this.isActing = false;
        this.moveState = null;
        this.direction = null;

        this.create(data);
    }
    Laya.class(Monster, "Game.Monster", _super);
    var _proto = Monster.prototype;
    _proto.destroy = function () {
        _super.prototype.destroy.call(this, true);
        
        this.type = null;
        this.boss = null;
        this.isActing = false;
        this.moveState = null;
        this.direction = null;
    }
    
    _proto.create = function (data) {
        var skin = MONSTER_SKIN_PATH + data.skinId;
        
        this.boss = utils.createSkeleton(skin);
        this.boss.play("wait_down", true);

        this.x = data.point.x * GAME_MOVE_RATE;
        this.y = data.point.y * GAME_MOVE_RATE;
        this.bossId = data.bossId;

        this.moveState = "wait";
        this.direction = "down";
        this.type = data.type;

        this.addChild(this.boss);
    }
    /**
     * @public
     * Boss向指定方向移动
     * @param {Object} data Boss移动数据
     * 
     * 示例:{"bossId":"1233455643",skinId:"1005","point":{"x":12,"y":18},"direction":"down","stop":0}
     * point:Boss当前位置
     * direction:Boss当前方向
     * stop:Boss当前状态 0:行走 1:停止
     */
    _proto.move = function (data) {
        var moveState = data.stop == 0 ? "move" : "wait";
        var direction = data.direction;

        this.x = data.point.x * GAME_MOVE_RATE;
        this.y = data.point.y * GAME_MOVE_RATE;
        this.zOrder = this.y;

        if(this.direction == direction && this.moveState == "move" && moveState == "move"){return;}
        
        this.moveState = moveState;
        this.direction = direction;
        
        if(!this.isActing){
            this.boss.play(moveState + "_" + direction, true);
        }
    }
    /**
     * Boss动作
     * @param {String} act 动作名
     * 动作名包含 困住:hit 死亡:die(播放一次)
     */
    _proto.act = function (act, callback) {
        this.isActing = true;
        this.boss.offAll(Laya.Event.STOPPED);
        console.log("Monster Action Start. Action:" + act);

        switch(act){
            case "die":
                switch(this.type){
                    case "boss":
                        this.boss.play("act_die", false);
                        this.boss.once(Laya.Event.STOPPED, this, function () {
                            Laya.Tween.to(this, {alpha : 0}, 500, null, Laya.Handler.create(this, function () {
                                console.log("Boss死亡");
                                this.visible = false;
                                this.alpha = 1;
                                callback && callback();
                            }));
                        });
                        break;
                    case "guard":
                        console.log("Monster Guard Died")
                        this.destroy(true);
                        callback && callback();
                        return;
                }
                break;
            case "trap":
                this.boss.play("act_trap", true);
                break;
            case "hit":
                this.boss.play("hit_" + this.direction, false);
                this.boss.once(Laya.Event.STOPPED, this, function () {
                    console.log("Monster Action Completed. moveState:" + this.moveState + "  direction:" + this.direction);
                    this.boss.play(this.moveState + "_" + this.direction, true);
                });
                break;
            default:
                this.boss.play("act_" + act, false);
                this.boss.once(Laya.Event.STOPPED, this, function () {
                    console.log("Monster Action Completed. moveState:" + this.moveState + "  direction:" + this.direction);
                    this.boss.play(this.moveState + "_" + this.direction, true);
                });
        }

        this.boss.once(Laya.Event.STOPPED, this, function () {
            this.isActing = false;
        });

    }
})(Laya.Sprite);